#include "stdafx.h"
#include "CmdHistoryManager.h"
#include "HC-MGDlg.h"
CmdHistoryManager * CmdHistoryManager::m_pCmdHistoryManager = NULL;
CmdHistoryManager::CmdHistoryManager(void)
{

}
CmdHistoryManager::~CmdHistoryManager(void)
{
}

void CmdHistoryManager::Undo()
{
	if (m_vecUndo.empty())
	{
		CHCMGDlg::m_pstWnd->SetMenuUndo(FALSE);
		return;
	}
	Command *cmd = m_vecUndo.at(m_vecUndo.size() - 1);
	cmd->Undo();
	m_vecUndo.pop_back();
	m_vecRedo.push_back(cmd);
	if (m_vecUndo.empty())
	{
		CHCMGDlg::m_pstWnd->SetMenuUndo(FALSE);
	}
	CHCMGDlg::m_pstWnd->SetMenuRedo(TRUE);
}

void CmdHistoryManager::Redo()
{
	if (m_vecRedo.empty())
	{
		CHCMGDlg::m_pstWnd->SetMenuRedo(FALSE);
		return;
	}
	Command *cmd = m_vecRedo.at(m_vecRedo.size() - 1);
	cmd->Redo();
	m_vecRedo.pop_back();
	m_vecUndo.push_back(cmd);
	if (m_vecRedo.empty())
	{
		CHCMGDlg::m_pstWnd->SetMenuRedo(FALSE);
	}
	CHCMGDlg::m_pstWnd->SetMenuUndo(TRUE);
}

void CmdHistoryManager::ReleaseInstacne()
{
	if (NULL != m_pCmdHistoryManager)
	{
		delete m_pCmdHistoryManager;
		m_pCmdHistoryManager = NULL;
	}
}